package org.item.customer.controller;

import org.item.common.bean.CustomerContacts;
import org.item.common.bean.Customers;
import org.item.common.service.ICustomerContactsService;
import org.item.common.util.ResultData;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("customercontacts")
public class CustomerContactsController {
    @Autowired
    ICustomerContactsService customerContactsService;

    @PostMapping("/")
    public ResultData insert(@RequestBody CustomerContacts customerContacts){
        CustomerContacts data= customerContactsService.insert(customerContacts);
        return ResultData.success(data);
    }

    @PutMapping("/")
    public ResultData update(@RequestBody CustomerContacts customerContacts){
        CustomerContacts data= customerContactsService.update(customerContacts);
        return  ResultData.success(data);
    }

    @DeleteMapping("/{id}")
    public ResultData delete(@PathVariable Integer id){
        int result=customerContactsService.delete(id);
        if(result>=1){
            return ResultData.success(200,"删除成功",null);
        }else {
            return ResultData.fail();
        }
    }

    @PutMapping("/{id}")
    public ResultData setPrimary(@PathVariable Integer id){
        int data= customerContactsService.setPrimary(id);
        return  ResultData.success(data);
    }
}
